5.3.3 APPX Application Design Manual

+ Chapter 1-1: Overview of Application Design
+ Chapter 1-2: Getting Started
+ Chapter 1-3: Data Dictionary
+ Chapter 1-4: Understanding Process Design
+ Chapter 1-5: Interprocess Communication
+ Chapter 1-6: Customizing Your Application
+ Chapter 1-7: The Documentation Facility
+ Chapter 1-8: Application Design Tools
+ Chapter 2-1: Data Dictionary Overview
+ Chapter 2-2: Data Dictionary Concepts
+ Chapter 2-3: Domains
+ Chapter 2-4: Files and Fields
+ Chapter 2-5: Work Fields
+ Chapter 3-1: Overview of APPX Processes
+ Chapter 3-2: Getting Started
+ Chapter 3-3: Process Definition
+ Chapter 3-4: Menu Processes
+ Chapter 3-5: Job Processes
+ Chapter 3-6: Input Processes
+ Chapter 3-7: Output Processes
+ Chapter 3-8: Update Processes
+ Chapter 3-9: Query Processes
+ Chapter 3-10: Inquiry Processes
+ Chapter 3-11: Status Processes
+ Chapter 3-12: Subroutine Processes
+ Chapter 3-13: Table Processes
+ Chapter 3-14: Automatic and Optional Children
+ Chapter 3-15: Using the Image Editor
+ Chapter 3-16: Using GUI Features of the Image Editor
+ Chapter 3-17: Using Event Points
+ Chapter 4-1: ILF Integration
+ Chapter 4-2: True/False Status Indicators
+ Chapter 4-3: Specifying Statements
+ Chapter 4-4: The ILF Editor
+ Chapter 4-5: The Appx ILF Debugger
- Chapter 4-6: ILF Keyword Reference
+ Chapter 4-7: Predefined Fields
+ Chapter 4-8: Runtime Subroutine's and Predefined Processes
+ Chapter 4-9: Appx Chart Director API

Chapter 4-6: ILF Keyword Reference

CALC


The CALC statement allows you to perform complex calculations in a single statement (refer to the COMPUTE statement for simpler calculations involving only two fields or a field and a constant). The result of the calculation is placed in any of the index predefined fields, A to Z or AI to ZI.

  ?????  CALC  ?? = ???????????????????????????????????????????????????????????
  (1)         (2)  (3)

(1) T/F execution conditions
(2) Receiver index PDF (A to Z, AI to ZI)
(3) Algebraic computation (59 characters max)

Using the Statement

The algebraic computation can contain index predefined fields A to Z and AI to ZI, numeric constants, operators (+, -, *, and /), and any number of levels of parentheses. The CALC statement performs operations according to the standard algebraic rules of precedence:

Unary negation (-) (i.e., reversing the signs on numbers),

Then, for the innermost pair of parentheses:

Multiplication (*) and division (/), which have precedence over

Addition (+) and subtraction (-)

Then, proceed to each succeeding layer of parentheses, if applicable.

Precision for the floating-point variables A to Z is a maximum of 15 total decimal positions. Precision for the integer variables AI to ZI is a maximum of 10 total decimal positions.

Standard Math Functions

APPX supports the use of several standard math functions in the CALC statement. To use one of these functions, specify the function name, followed by its arguments in parentheses. For instance:

       CALC A = @ABS(B)

In this case, the absolute value of B (the argument) is assigned to A.

The function arguments can be expressions that may contain other functions. For instance, the following CALC statements are legal:

       CALC A  = @POW(B,1/3))

... takes the cube root of B

       CALC A  = @SQRT(@POW(B-C,2)+@POW(D-E,2))

... computes the absolute distance between two Cartesian points

APPX does not check for illegal argument values (such as taking the square root of a negative number). In general, you should check arguments for validity before using them in certain functions. If an error occurs, standard OVERFLOW processing takes place (you can tell where an error occurred, but not what caused it). The math functions fall into three groups described in corresponding sections: basic functions, exponential functions, and trigonometric functions.

Restrictions

The fields referenced in a CALC statement are restricted to the index predefined fields (A to Z and AI to ZI). Therefore, you frequently precede a CALC statement with one or more SET statements to move values into such fields, as in the following example:

         *
         *    A = Unit price 
         *    B = Quantity ordered
         *    C = Extension
         *
         SET  --- A  =  TOE ORDER UNIT PRICE 
         SET  --- B  =  TOE ORDER QUANTITY
         C = A*B
         SET  TOE ORDER AMOUNT   =  --- C

Note the use of comments to clarify the variable names used in the calculation. You may find it helpful to include comments whenever predefined variable names are used.

Compilation Errors

If the algebraic expression is invalid, a compilation error occurs. Invalid algebraic expressions include those with too few operands per operator and those with unbalanced parentheses.

Execution Errors

A runtime error can occur if an intermediate or final calculation results in overflow or division by zero.

Related Statements

COMPUTE, SET, OVERFLOW

Example

The following example demonstrates a calculation involving three index variables (B, C, and DI). The results are then placed in the receiver index variable (AI).


        **   The following statements calculate the total estimated monthly
        *    compensation (AI) for a salesperson. This formula includes a 
        *    fixed monthly base salary ($1,800), an annual bonus (B), and a
        *    commission based on the number of units sold (DI) over 100 
        *    times the average sale (C) less $50 per unit. The bonus and 
        *    comission are annualized so they need to be divided by 12
        *    to derive a monthly amount
        *
        SET  --- B  =  TSA SALES ANNUAL BONUS 
        SET  --- C  =  TSA SALES AVG UNIT SALE 
        READ TAR CUSTOMER   HOLD 0 FT 0 BY CUSTOMER NO
        SET  --- DI =  TSA SALES NO UNITS SOLD
        SET  TSA SALES MONTHLY SALARY   =  --- AI 
  

In this example, the constant 50 is subtracted from the predefined field C, and the constant 100 is subtracted from the predefined field DI, before the two intermediate results are multiplied together. Next, B is added to the result of the multiplication, and that result is divided by 12. Finally, that result is added to 1800, rounded to an integer, and stored in AI.

 In this example, note that only the predefined field AI is affected. The fields B, C, and DI remain unaltered.

Application Design Manual                                         "Powered by Appx Software"

619

©2006 By APPX Software, Inc. All Rights Reserved